#ifndef __APP_FP256_360_H__
#define __APP_FP256_360_H__

#include "usb_device.h"

#define FP_USER_MODE_FLAG   "USER"  //用户模式
#define FP_DEBUG_MODE_FLAG  "TEST"  //调试模式

#define CHIP_ADDR_SIZE          4
#define PACKET_FLAG_SIZE        1
#define PACKET_LEN_SIZE         2
#define CHIP_CHECKSUM_SIZE      2

#define FINGER_ENROLL_INIT      0   
#define FINGER_ENROLL_START     1
#define FINGER_ENROLL_END       2
#define FINGER_ENROLL_ERROR     0x0F


    
#define  ERROR_CODE_OK                0
#define  ERROR_CODE_ERASE_FAIL        1
#define  ERROR_CODE_WRITE_FAIL        2

#define FLASH_INFO_PAGE_SIZE        128 //flash信息页大小

#define INDEX_PAGE_NUM              1//只支持1页索引表


#define FP_ENROLL_ID_MIN    0
#define FP_ENROLL_ID_MAX    (256*INDEX_PAGE_NUM - 1)    //1023


typedef enum _FP_PC_STATE_TYPE_ENUM_
{
    FP_PC_S0_STATE_TYPE = 0x00,
    FP_PC_S1_STATE_TYPE = 0x01,
    FP_PC_S2_STATE_TYPE = 0x02,
    FP_PC_S3_STATE_TYPE = 0x03,
    FP_PC_S4_STATE_TYPE = 0x04,
    FP_PC_S5_STATE_TYPE = 0x05,
    FP_PC_MS_STATE_TYPE = 0x10,
}FP_PC_STATE_TYPE_ENUM;


typedef enum _FP_OS_TYPE_ENUM_
{
    FP_WINDOWS_OS_TYPE = 0, //windows
    FP_KYLIN_OS_TYPE = 1,   //麒麟
    FP_UOS_OS_TYPE = 2,     //统信操作系统
    FP_NFS_OS_TYPE = 3,     //方德操作系统
    FP_ALL_OS_TYPE = 0xff,  //搜索全部
    FP_NONE_OS_TYPE = 0xffff,
}FP_OS_TYPE_ENUM;

#if 1//最多录入30枚指纹
#define WINDOWS_ENROLL_ID_MIN   0
#define WINDOWS_ENROLL_ID_MAX   29

#define KYLIN_ENROLL_ID_MIN 30
#define KYLIN_ENROLL_ID_MAX 59

#define UOS_ENROLL_ID_MIN   60
#define UOS_ENROLL_ID_MAX   89

#define NFS_ENROLL_ID_MIN   90  //方德操作系统
#define NFS_ENROLL_ID_MAX   119
#else//最多录入20枚指纹
#define WINDOWS_ENROLL_ID_MIN   10
#define WINDOWS_ENROLL_ID_MAX   29

#define KYLIN_ENROLL_ID_MIN 40
#define KYLIN_ENROLL_ID_MAX 59

#define UOS_ENROLL_ID_MIN   70
#define UOS_ENROLL_ID_MAX   89

#define NFS_ENROLL_ID_MIN   100 //方德操作系统
#define NFS_ENROLL_ID_MAX   119
#endif


#define CURRENT_WINDOWS_OS_TYPE 0
#define CURRENT_KYLIN_OS_TYPE   0
#define CURRENT_UOS_OS_TYPE     1
#define CURRENT_NFS_OS_TYPE     0
#define CURRENT_ALL_OS_TYPE     0   //默认UOS操作系统，搜索时全部比对
#define CURRENT_NONE_OS_TYPE    0   //协议不区分操作系统

#if CURRENT_WINDOWS_OS_TYPE
    #define CURRENT_ENROLL_ID_MIN WINDOWS_ENROLL_ID_MIN
    #define CURRENT_ENROLL_ID_MAX WINDOWS_ENROLL_ID_MAX
    #define FP_CURRENT_OS_TYPE FP_WINDOWS_OS_TYPE
#elif CURRENT_KYLIN_OS_TYPE
    #define CURRENT_ENROLL_ID_MIN KYLIN_ENROLL_ID_MIN
    #define CURRENT_ENROLL_ID_MAX KYLIN_ENROLL_ID_MAX
    #define FP_CURRENT_OS_TYPE FP_KYLIN_OS_TYPE
#elif CURRENT_UOS_OS_TYPE
    #define CURRENT_ENROLL_ID_MIN UOS_ENROLL_ID_MIN
    #define CURRENT_ENROLL_ID_MAX UOS_ENROLL_ID_MAX
    #define FP_CURRENT_OS_TYPE FP_UOS_OS_TYPE
#elif CURRENT_NFS_OS_TYPE
    #define CURRENT_ENROLL_ID_MIN NFS_ENROLL_ID_MIN
    #define CURRENT_ENROLL_ID_MAX NFS_ENROLL_ID_MAX
    #define FP_CURRENT_OS_TYPE FP_NFS_OS_TYPE
#elif CURRENT_ALL_OS_TYPE
    #define CURRENT_ENROLL_ID_MIN UOS_ENROLL_ID_MIN
    #define CURRENT_ENROLL_ID_MAX UOS_ENROLL_ID_MAX
    #define FP_CURRENT_OS_TYPE FP_ALL_OS_TYPE
#elif CURRENT_NONE_OS_TYPE
    #define CURRENT_ENROLL_ID_MIN UOS_ENROLL_ID_MIN
    #define CURRENT_ENROLL_ID_MAX UOS_ENROLL_ID_MAX
    #define FP_CURRENT_OS_TYPE 0    
#endif

#define ENROLL_NUM_MAX  (CURRENT_ENROLL_ID_MAX - CURRENT_ENROLL_ID_MIN + 1)//最大录入次数


/*********************用于BF91360ML*********************/
#define IMG_SIZE    (256*360)     

#define USB_BUFFER_SIZE   (IMG_SIZE+1000)

#define CAP_PARAM_VALID_FLAG (0x55AA)

#define CAP_PARAM_DEFAULT_BRIGHTNESS (0x0077)
#define CAP_PARAM_BRIGHTNESS_MIN (0x0000) //(0x0072) //验证亮度范围, modified by hcq, 20220103
#define CAP_PARAM_BRIGHTNESS_DEFAULT_MIN 0x0072 //亮度默认最小值
#define CAP_PARAM_BRIGHTNESS_MAX (0x00ff)
#define CAP_PARAM_BRIGHTNESS_DEFAULT_MAX (0x00ff)
#define CAP_PARAM_BRIGHTNESS_OFFSET 0 //1//亮度值偏差范围, 验证亮度范围, modified by hcq, 20220103

#define CAP_PARAM_DEFAULT_CONTRAST (0x0057)

#define CAP_PARAM_WIDTH_MAX 256
#define CAP_PARAM_WIDTH_MIN 32
#define CAP_PARAM_HEIGHT_MAX 360
#define CAP_PARAM_HEIGHT_MIN 32
/*******************************************************/


#define  PROT_RESP_PAGEID_BEYOND_DATABASE   0x02    //页ID超过物理空间
#define  PROT_RESP_PAGEID_INVALID           0x03    //页ID无效

#define  PROT_RESP_CMD_EXE_ERR  0x0d    //指令执行错误
#define  PROT_RESP_PWD_ERROR    0x13    //口令不正确

#define  PARAM_FINGER_OK        0x00
#define  PARAM_CAPTURE_IMG      0x01
#define  PARAM_GEN_CHAR         0x02
#define  PARAM_FINGER_OFF       0x03
#define  PARAM_IMG_COMP         0x05

#define  AUTOENROLL_TIMES_MAX   6   //自动录入模板最大次数


/***********************枚举类型************************/

typedef enum _FP_CONTROL_FLAG_ENUM_
{
    FP_CONTROL_FLAG_IDLE =0,
    FP_CONTROL_FLAG_STOPPED = 1,
    FP_CONTROL_FLAG_TIMEOUT,
    FP_CONTROL_FLAG_DEV_NOT_EXIST,
    FP_CONTROL_FLAG_ENROLLID_OUT_RANGE,
}FP_CONTROL_FLAG_ENUM;


//协议包标识类型
typedef enum _PROT_TYPE_ENUM_
{
    PROT_TYPE_CMD       = 0x01,
    PROT_TYPE_DATA      = 0x02,
    PROT_TYPE_RESPOND   = 0x07,
    PROT_TYPE_END       = 0x08,
}PROT_TYPE_ENUM;

//协议指令类型
typedef enum _PROT_CMD_ENUM_
{
    PROT_CMD_GETIMAGE = 0x01,       //验证用获取图像
    PROT_CMD_GENCHAR = 0x02,        //根据原始图像生成指纹特征存于文件缓冲区 
    PROT_CMD_MATCH = 0x03,          //精确比对特征文件缓冲区中的特征文件
    PROT_CMD_SEARCH = 0x04,         //以特征文件缓冲区中的特征文件搜索整个或部分指纹库 
    PROT_CMD_REGMODEL = 0x05,       //将特征文件合并生成模板存于特征文件缓冲区 
    PROT_CMD_STORECHAR = 0x06,      //将特征缓冲区中的文件储存到flash指纹库中
    PROT_CMD_LOADCHAR = 0x07,       //从 flash 指纹库中读取一个模板到特征缓冲区 
    PROT_CMD_UPCHAR = 0x08,         //将特征缓冲区中的文件上传给上位机
    PROT_CMD_DOWNCHAR = 0x09,       //从上位机下载一个特征文件到特征缓冲区
    PROT_CMD_UPIMAGE = 0x0A,        //上传原始图像    
    PROT_CMD_DOWNIMAGE = 0x0B,      //下载原始图像
    PROT_CMD_DELCHAR = 0x0C,        //删除 flash 指纹库中的一个特征文件  
    PROT_CMD_EMPTY = 0x0D,          //清空 flash 指纹库  
    PROT_CMD_READSYSPARA = 0x0F,    //读系统基本参数
    PROT_CMD_SETPWD = 0x12,         //设置设备握手口令
    PROT_CMD_VFYPWD = 0x13,         //验证设备握手口令

    PROT_CMD_SETCHIPADDR = 0x15,    //设置芯片地址
    PROT_CMD_READINFOPAGE = 0x16,   //读取 FLASH Information Page 内容
    PROT_CMD_HIGHSPEEDSEARCH = 0x1B,    //高速搜索FLASH 
    PROT_CMD_VALIDTEMPLATENUM = 0x1D,   //读有效模板个数   
    PROT_CMD_READINDEXTABLE = 0x1F,     //读索引表
    PROT_CMD_GETENROLLIMAGE = 0x29, //注册用获取图像   
    PROT_CMD_CANCEL = 0x30,         //取消指令  
    PROT_CMD_AUTOENROLL = 0x31,     //自动注册模块指令  
    PROT_CMD_AUTOIDENTIFY = 0x32,   //自动验证指纹指令  
    PROT_CMD_SLEEP = 0x33,          //休眠指令  
    PROT_CMD_GETCHIPSN = 0x34,      //获取芯片唯一序列号
    PROT_CMD_HANDSHAKE = 0x35,      //握手指令
    PROT_CMD_CHECKSENSOR = 0x36,    //校验传感器 
    PROT_CMD_IIC_LED_CONTROL = 0x40,//IIC接口灯光控制

    PROT_CMD_PS_PC_STATE = 0x50,//下发PC状态

    PROT_CMD_TEST_TYPE = 0xAF,          //生产测试命令
    
    /*********************用于BF91360ML*********************/
    PORT_CMD_SET_BRIGHTNESS = 0xB0,     //设置采集器亮度, add by hcq, 20221229
    PORT_CMD_GET_BRIGHTNESS = 0xB1,     //获取采集器当前亮度
    PORT_CMD_SET_CONTRAST = 0xB2,       //设置采集器当前对比度
    PORT_CMD_GET_CONTRAST = 0xB3,       //获取采集器当前对比度
    PORT_CMD_GET_MAXSIZEOFIMAGE = 0xB4, //获取采集器图片尺寸最大值
    PORT_CMD_SET_SIZEOFIMAGE = 0xB5,    //设置采集器当前图片坐标X，坐标Y，宽度，高度
    PORT_CMD_GET_SIZEOFIMAGE = 0xB6,    //获取采集器当前图片坐标X，坐标Y，宽度，高度
    PORT_CMD_READYCAPIMAGE = 0xB7,      //准备采集一帧图像
    PORT_CMD_STARTCAPIMAGE = 0xB8,      //采集一帧图像
    PORT_CMD_ENDCAPIMAGE = 0xB9,        //结束采集一帧图像
    
    PORT_CMD_ACQUIRE_IMAGEDATA = 0xF0,  //自定义获取图像数据状态, add by hcq, 20230118
    /*******************************************************/

    PROT_CMD_RTBOOT = 0xFF, //返回boot状态，便于下次重烧固件
}PROT_CMD_ENUM;

typedef enum _PROT_SUBCMD_ENUM_
{
    PROT_SUBCMD_READ_FW = 0x10,         //读取固件版本号
    PROT_SUBCMD_RW_REG = 0x11,          //读写寄存器
    PROT_SUBCMD_FP_DOWN = 0x13,         //检测手指按下
    PROT_SUBCMD_SIMFP_DOWN = 0x14,      //检测假手指按下

    PROT_SUBCMD_DEADPIXEL = 0x18,       //坏点检测
    PROT_SUBCMD_CLEAR_IRQ = 0x19,       //清除sensor中断
    PROT_SUBCMD_SENSORINIT = 0x22,      //Sensor init 初始化结果
    PROT_SUBCMD_SELFCHECK = 0x31,       //自检指令
    PROT_SUBCMD_SPI_TEST = 0x32,        //进入图像质量测试模式
    PROT_SUBCMD_OTP_WRITE = 0x34,       //OTP信息烧录模式
    PROT_SUBCMD_OTP_READ = 0x35,        //OTP信息读取模式
    PROT_SUBCMD_SPI_INT = 0x36,         //检测SPI中断信号
    PROT_SUBCMD_I2C_INT = 0x37,         //检测I2C中断信号
    PROT_SUBCMD_RECOVER_FACTORY = 0x38, //恢复出厂设置
    PROT_SUBCMD_EXFLASH_ID = 0x39,      //获取片外flashID

    PROT_SUBCMD_SET_MODE = 0xbd,            //设置用户模式或调试模式
}PROT_SUBCMD_ENUM;
#define PROT_CMD_DEBUG_TYPE             0xDE        //调试指令 de 01: 打开调试指令，de 00：关闭调试

typedef enum _PROT_CMD_RESP_ENUM_
{
    PROT_RESP_OK = 0x00,
    PROT_RESP_DATA_RECV_ERR = 0x01,         //数据包接收错误
    PROT_RESP_NO_FINGER = 0x02,             //传感器上无手指
    PROT_RESP_ENROLL_FAULT = 0x03,          //录入指纹图像失败
    PROT_RESP_IMG_TOO_DRY = 0x04,           //录入指纹图像太干、太淡而生不成特征
    PROT_RESP_IMG_TOO_WET = 0x05,           //录入指纹图像太湿、太糊而生不成特征
    PROT_RESP_IMG_TOO_CHAOTIC = 0x06,       //录入指纹图像太乱而生不成特征
    PROT_RESP_FEATURE_TOO_LOW = 0x07,       //指纹图像特征点太少（或面积太小）而生不成特征
    PROT_RESP_FPRINT_MISMATCH = 0x08,       //指纹不匹配
    PROT_RESP_FPRINT_NOT_FIND = 0x09,       //没搜索到指纹
    PROT_RESP_FEATURE_MERGE_FAULT = 0x0A,   //特征合并失败
    PROT_RESP_ADDR_OUT_RANGE = 0x0B,        //访问指纹库时地址范围超出
    PROT_RESP_READ_TEMPLATE_FAULT = 0x0C,   //从指纹库读模板出错或无效
    PROT_RESP_UPLOAD_FEATURE_FAULT = 0x0D,  //上传特征失败
    PROT_RESP_CANT_RECV_PKG = 0x0E,         //模块不能接收后续数据包
    PROT_RESP_UPLOAD_IMG_FAULT = 0x0F,      //上传图像失败
    PROT_RESP_DEL_TEMPLATE_FAULT = 0x10,    //删除模板失败
    PROT_RESP_CLEAN_FPRINTLIB_FAULT = 0x11, //清空指纹库失败
    PROT_RESP_CANTBE_LOWPOWER_STATE = 0x12, //不能进入低功耗状态
    PROT_RESP_CMD_ERR = 0x13,               //口令不正确
    PROT_RESP_RESET_FAULT = 0x14,           //系统复位失败
    PROT_RESP_NO_RAWIMG_IN_BUFFER = 0x15,   //缓冲区内没有原始图而生不成图像
    PROT_RESP_UPGRADE_FAULT = 0x16,         //在线升级失败
    PROT_RESP_FINGER_NO_MOVE = 0x17,        //残留指纹或两次采集之间手没有移动过
    PROT_RESP_WR_FLASH_FAULT = 0x18,        //读写FLASH出错
    PROT_RESP_CREATE_RANDOM_NUM_FAULT = 0x19,   //随机数生成失败
    PROT_RESP_NOT_VALID_REG_NUM = 0x1A,     //无效寄存器号
    PROT_RESP_REG_VALUE_ERR = 0x1B,         //寄存器设定内容错误号
    PROT_RESP_NOTEPAD_PAGE_NUM_ERR = 0x1C,  //记事本页码指定错误
    PROT_RESP_OPT_PORT_FAULT = 0x1D,        //端口操作失败
    PROT_RESP_AUTO_REGISTER_FAULT = 0x1E,   //自动注册失败
    PROT_RESP_FPRINTLIB_FULL = 0x1F,        //指纹库满
    PROT_RESP_DEV_ADDR_ERR = 0x20,          //设备地址错误
    PROT_RESP_PASSWORD_ERR = 0x21,          //密码有误
    PROT_RESP_TEMPLATE_NOT_EMPTY = 0x22,    //指纹模板非空
    PROT_RESP_TEMPLATE_EMPTY = 0x23,        //指纹模板为空
    PROT_RESP_FPRINTLIB_EMPTY = 0x24,       //指纹库空
    PROT_RESP_ENROLL_TIMES_ERR = 0x25,      //录入次数设置错误
    PROT_RESP_TIMEOUT = 0x26,               //超时
    PROT_RESP_FPRINT_EXIST = 0x27,          //指纹已存在
    PROT_RESP_TEMPLATE_RELATED = 0x28,      //指纹模板有关联
    PROT_RESP_SENSOR_INIT_FAULT = 0x29,     //传感器初始化失败

    PROT_RESP_POSITION_REPEATED = 0x30,     //位置重复
    PROT_RESP_FPRINT_QUALITY_BAD = 0x31,    //指纹质量不佳
    PROT_RESP_FPRINT_AREA_TOO_SMALL = 0x32, //指纹面积过小

    PROT_RESP_DATA_RECV_OK = 0xF0,          //有后续数据包的指令，正确接收后用0xf0应答
    PROT_RESP_DATA_CMD_RECV_OK = 0xF1,      //有后续数据包的指令，命令包用0xf1应答
    
    PROT_RESP_PROG_FLASH_CHECKSUM_ERR = 0xF2,       //烧写内部FLASH时，校验和错误
    PROT_RESP_PROG_FLASH_PKGTYPE_ERR = 0xF3,        //烧写内部FLASH时，包标识错误
    PROT_RESP_PROG_FLASH_PKGLEN_ERR = 0xF4,         //烧写内部FLASH时，包长度错误
    PROT_RESP_PROG_FLASH_PKGLEN_TOO_LANG = 0xF5,    //烧写内部FLASH时，包长度太长
    PROT_RESP_PROG_FLASH_FAULT = 0xF6,              //烧写内部FLASH失败
}PROT_CMD_RESP_ENUM;



/*256*360指纹模组协议头部*/
typedef struct _MSG_HEAD_STRUCT_
{
    uint16 pkg_head;      //包头，固定为0xEF01
    uint32 chip_addr;    //芯片地址,默认为0xffffffff
    uint8  pkg_flag;  //包标识
    uint16  pkg_len; //包长度  
}__attribute__((packed))MSG_HEAD_STRUCT;

typedef struct _MSG_STRUCT_
{
    MSG_HEAD_STRUCT head;      //消息头部
    uint8 data[USB_BUFFER_SIZE];
    uint16 check_sum;
}__attribute__((packed))MSG_STRUCT;

/*协议包数据结构*/
typedef struct _PROT_PACKET_
{
    uint8  prot_state;          //串口协议解析状态
    uint16 prot_head;
    uint32 prot_addr;
    uint8  prot_type;
    uint16 prot_size;
    uint8  prot_data[USB_BUFFER_SIZE];  //保存上位机的参数数据
    uint32 prot_data_cnt;       //对数据长度进行计数
    uint16 prot_checksum;
    uint8  prot_respond;        //给host的应答
    uint8  prot_source;         //数据从UART或SPI过来的,UART:0 ;SPI:1
    
    uint8  current_cmd_code;    //当前发送的指令码, add by hcq, 20230117
    uint8  current_resp_cmd;    //当前应答的命令
    uint8  current_resp_type;   //当前应答结果
    //uint8  recv_prot_type;
    uint8  current_sub_cmd_code;    //生产测试模式下的子指令码
}PROT_PACKET;

/*标识包处理状态机*/
enum 
{
    PACKET_IDLE = 0,          
    PACKET_HEAD,              
    PACKET_ADDRESS1,          
    PACKET_ADDRESS2,                
    PACKET_ADDRESS3,               
    PACKET_ADDRESS4,          
    PACKET_TYPE,
    PACKET_SIZE1,
    PACKET_SIZE2,
    PACKET_DATA,
    PACKET_CHECKSUM1,
    PACKET_CHECKSUM2,
    PACKET_ERROR = 100,  //包出错
};

/*确认码标识处理结果, 用于BF91360ML*/
typedef enum _CONFIRM_CODE_ENUM_
{
    CONFIRM_CODE_SUCCESS = 0x00,  //执行成功        
    CONFIRM_CODE_CMD_ERROR = 0x01,//指令错误    
    CONFIRM_CODE_EXECUTE_FAILED = 0x02, //执行失败         
}CONFIRM_CODE_ENUM;
/***********************************/

/*读取数据操作相关参数*/
typedef struct _RECV_DATA_STRUCT_
{
    int32  recv_len;            //串口协议解析状态
    uint16 wait_ms;             //首次读取数据间隔时间
    uint16 cycle_times;         //未读到数据时循环读取次数, 至少循环1次
    uint16 cycle_ms;            //循环等待时间
}RECV_DATA_STRUCT;


/*系统基本参数，待确认格式*/
typedef struct _FP_SYS_PARAM_STRUCT_
{
    uint16 sensor_type;         //传感器类型
    uint16 fp_database_size;    //指纹库容量
    uint16 security_level;      //安全等级
    uint32 device_addr;         //设备地址
}FP_SYS_PARAM_STRUCT;

/*自动录入模板参数*/
typedef struct _FP_AUTOENROLL_PARAM_STRUCT_
{
    uint16 enroll_id;   //自动注册ID
    uint8 auto_enroll_times;        //自动注册模板次数
    uint8 validity_check_result;    //合法性检测结果
    uint8 current_enroll_time;      //当前录入次数
    uint8 current_enroll_flag;      //当前录入结束标志，0: 未结束，1: 结束
    uint8 capture_result[AUTOENROLL_TIMES_MAX+1];   //当前采图结果，下标1开始
    uint8 create_feature_result[AUTOENROLL_TIMES_MAX+1];    //当前生成特征结果，下标1开始
    uint8 enroll_result[AUTOENROLL_TIMES_MAX+1];    //当前录入结果，下标1开始
    uint8 merge_template_result;    //合并模板结果
    uint8 enroll_conflict_result;   //已注册检测结果
    uint8 store_template_result;    //模板存储结果
    uint8 enroll_finish_flag;   //自动录入结束标志，0: 未结束，1: 结束
    
}FP_AUTOENROLL_PARAM_STRUCT;


/*自动验证指纹参数*/
typedef struct _FP_AUTOIDENTIFY_PARAM_STRUCT_
{
    uint8 security_level;   //安全等级
    uint16 identify_id; //自动注册ID
    uint16 param;   //参数    

    uint8 validity_check_result;    //合法性检测结果
    uint8 capture_result;   //当前采图结果
    uint8 search_result;    //搜索结果
    int32 search_num;       //搜索比对成功的指纹数量
    uint16 search_id[ENROLL_NUM_MAX];       //搜索成功对应的id
    uint16 score;           //比对得分
    
    uint8 identify_finish_flag; //自动录入结束标志，0: 未结束，1: 结束
    
}FP_AUTOIDENTIFY_PARAM_STRUCT;

/*一键开机相关参数*/
typedef struct _FP_ONEKEY_POWERUP_STRUCT_
{
    uint8 onekey_powerup_flag;  //一键开机标志，1: 收到一键开机结果，0: 未收到一键开机结果
    
    int32 search_num;       //一键开机搜索比对成功的指纹数量
    uint16 search_id[ENROLL_NUM_MAX];       //一键开机搜索成功对应的id
    struct timeval tv_current_time;         //一键开机读取到的时间

    uint8 onekey_restart_flag;                      //0: 非休眠或睡眠一键开机；1:休眠或睡眠一键开机
    
    uint8 continue_read_fw_version_flag;    //1: 读取版本信息时未读到对应结果则继续读取, 0: 无需继续读读取版本信息
    struct timeval tv_restart_begin;
    
}FP_ONEKEY_POWERUP_STRUCT;



/*指纹模组相关参数*/
typedef struct _FP_DEVICE_PARAM_STRUCT_
{
    USB_DEV_STRUCT usb_dev;

    PROT_PACKET prot_packet_usb;
    uint8  usb_recv_data[USB_BUFFER_SIZE];
    uint16 usb_recv_cnt;
    
    uint8 img_data[IMG_SIZE];       //指纹图片原始数据
    
    FP_SYS_PARAM_STRUCT sys_param;  //系统参数
    
    uint32 chip_addr;               //芯片地址
    
    uint8 flash_info_page[FLASH_INFO_PAGE_SIZE];        //Flash信息页

    uint8 index_table_page; //待读取索引表页码
    uint8 index_table_info[4][32];//索引表信息

    uint8 chip_serial_num_len;
    uint8 chip_serial_num[32];//芯片唯一序列号

    uint8 handshake_state;          //握手状态, 0: 未收到握手, 1: 收到握手

    FP_AUTOENROLL_PARAM_STRUCT auto_enroll_param;
    
    FP_AUTOIDENTIFY_PARAM_STRUCT auto_identify_param;//自动验证指纹

    uint8 delete_template_result;   //删除模板指令结果

    uint8 empty_template_result;    //清空指纹库结果

    uint8 cancel_result;            //取消指令结果

    uint8 sleep_result;             //休眠指令结果

    uint16 valid_template_num;      //有效模板个数

    char firmware_version[64];
    uint32 firmware_version_num;
    char firmware_version_new[64];

    int ctrlFlag;

    FP_ONEKEY_POWERUP_STRUCT onekey_powerup; //一键开机相关参数
        
}FP_DEVICE_PARAM_STRUCT;

extern int32 fp_module_init(FP_DEVICE_PARAM_STRUCT *this);
//extern int ofp1234_discover(bio_dev *dev);
extern int fp_get_device_num(FP_DEVICE_PARAM_STRUCT *this);
extern int32 fp_read_invalid_pkg(FP_DEVICE_PARAM_STRUCT *this, int count);
extern int32 fp_cancel(FP_DEVICE_PARAM_STRUCT *this);
extern uint16 fp_get_empty_enroll_id(FP_DEVICE_PARAM_STRUCT *this);
extern int32 fp_auto_enroll_start(FP_DEVICE_PARAM_STRUCT *this, uint16 enroll_id, uint8 enroll_times, uint16 param);
extern int32 fp_auto_enroll(FP_DEVICE_PARAM_STRUCT *this, int32 timeout_ms);
extern uint8 fp_get_current_enroll_time(FP_DEVICE_PARAM_STRUCT *this);
extern uint8 fp_get_enroll_create_feature_result(FP_DEVICE_PARAM_STRUCT *this, uint8 enroll_time);
extern uint8 fp_get_enroll_result(FP_DEVICE_PARAM_STRUCT *this, uint8 enroll_time);
extern int32 fp_auto_identify(FP_DEVICE_PARAM_STRUCT *this, uint8 security_level, uint16 identify_id, uint16 param, uint16 *identify_result_id, int32 timeout_ms);
extern int32 fp_delete_template(FP_DEVICE_PARAM_STRUCT *this, uint16 enroll_id, uint16 num);

extern int32 fp_delete_invalid_template(FP_DEVICE_PARAM_STRUCT *this, uint8 *index_list);
extern int fp_set_mode(FP_DEVICE_PARAM_STRUCT *this, char *mode, int len);
extern int32 fp_set_ctrlFlag(FP_DEVICE_PARAM_STRUCT *this, int32 ctrlFlag);
extern int32 fp_get_ctrlFlag(FP_DEVICE_PARAM_STRUCT *this);
extern uint8 fp_get_enroll_finish_flag(FP_DEVICE_PARAM_STRUCT *this);

extern int fp_reboot(FP_DEVICE_PARAM_STRUCT *this);
extern int32 fp_get_firmware_version(FP_DEVICE_PARAM_STRUCT *this);
extern char *fp_return_firmware_version(FP_DEVICE_PARAM_STRUCT *this);
extern int fp_set_pc_state(FP_DEVICE_PARAM_STRUCT *this, uint8 pc_state);
extern int32 fp_get_increment_of_time_ms(struct timeval *tv_old);
extern struct timeval *get_onekey_powerup_tv_time(FP_DEVICE_PARAM_STRUCT *this);            //一键开机读取到的时间
extern uint8 get_onekey_powerup_flag(FP_DEVICE_PARAM_STRUCT *this); //获取一键开机标志
extern uint16 *get_onekey_powerup_search_id(FP_DEVICE_PARAM_STRUCT *this);
extern int32 get_onekey_powerup_search_num(FP_DEVICE_PARAM_STRUCT *this);
extern int32 set_onekey_powerup_flag(FP_DEVICE_PARAM_STRUCT *this, uint8 flag);
extern int32 init_onekey_powerup_search_id(FP_DEVICE_PARAM_STRUCT *this);
extern int32 fp_onekey_powerup_identify(FP_DEVICE_PARAM_STRUCT *this, uint8 security_level, uint16 identify_id, uint16 param, uint16 *identify_result_id, int32 wait_ms);
extern int32 fp_onekey_restart_identify_2(FP_DEVICE_PARAM_STRUCT *this, uint16 *identify_result_id);
extern uint8 get_onekey_restart_flag(FP_DEVICE_PARAM_STRUCT *this);
extern int32 set_onekey_restart_flag(FP_DEVICE_PARAM_STRUCT *this, uint8 flag);
extern uint32 fp_return_firmware_version_num(FP_DEVICE_PARAM_STRUCT *this);
extern int32 get_restart_tv_begin_change_ms(FP_DEVICE_PARAM_STRUCT *this);
extern uint8 fp_get_identify_validity_check_result(FP_DEVICE_PARAM_STRUCT *this);










#endif

